"""Regular Expression Examples
from http://www.swc.scipy.org/lec/re.html
"""

import re

dragons = [
    ['CTAGGTGTACTGATG',    'Antipodean Opaleye'],
    ['AAGATGCGTCCGTAT',    'Common Welsh Green'],
    ['AGTCGTGCTCGTTATATC', 'Hebridean Black'],
    ['ATGCGTCGTCGATTATCT', 'Hungarian Horntail'],
    ['CCGTTAGGGCTAAATGCT', 'Norwegian Ridgeback']
]

for (dna, name) in dragons:
    if re.search('ATGCGT', dna):
        print name,
print
        
for (dna, name) in dragons:
    if re.search('ATGCGT|GCT', dna):
        print name,
print 

tests = [
    ['TTACTA',    True],  # separated by zero G's
    ['TTAGCTA',   True],  # separated by one G
    ['TTAGGGCTA', True],  # separated by three G's
    ['TTAXCTA',   False], # an X in the way
    ['TTAGCGCTA', False], # an embedded X in the way
]

for (dna, expected) in tests:
#    actual = re.search('TTAG*CTA', dna) is not None
#    assert actual == expected
    print re.search('TTAG*CTA', dna) is not None, expected
    
        
    